import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout'
import pages from './pages'
import store from '@/store'
import { Notification, MessageBox, Message, Loading } from 'element-ui'
Vue.use(VueRouter)
// 页面子路由
// const viewsList = [...views]

const routes = [
  {
    path: '/',
    name: 'layout',
    redirect: '/index',
    component: Layout,
    children: [],
    meta: {
      title: 'layout',
      noNeedLogin: true,
      icon: ''
    }
  },
  // 公共路由
  ...pages
]
// 获取原型对象push函数
const originalPush = VueRouter.prototype.push

// 获取原型对象replace函数
const originalReplace = VueRouter.prototype.replace

// 修改原型对象中的push函数
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 修改原型对象中的replace函数
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err)
}

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
